package com.ht.config;

import com.ht.job.QuartzJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JobConfig {

    /**
     * 创建jobDetail
     * @return
     */
    @Bean
    public JobDetail jobDetail(){
        return JobBuilder.newJob(QuartzJob.class)//绑定job
                .withIdentity("job","jobGroup")//job：名  jobGroup：组名
                .usingJobData("jobKey","查询成功")//jobData的key和值
                .storeDurably()
                .build();
    }

    /**
     * 创建Trigger
     * @return
     */
    @Bean
    public Trigger trigger(){
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())//绑定jobDetail
                .withIdentity("trigger","triggerGroup")
                .usingJobData("triggerKey","Hello trigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 */0 * * ?"))//cron表达式  每5秒执行一次
                .build();
    }

}
